global ptypes
ptypes=["series","movies"]
def is_valid(db,product_id,ptype,remote_id):
	cur=db.cursor()
	##TODO XSS / SQL INJ.
	qry="select id from "+ ptypes[ptype] + " where id=%s and remote_identifier=%s"
	cur.execute(qry,(product_id,remote_id))
	cnt=cur.fetchone()
	cur.close()
	if not cnt is None:
		return True
	else:
		return False

def get_id(db,product_name,ptype,remote_id):
	global ptypes
	cur=db.cursor()
	##TODO XSS / SQL INJ.
	qry="select id from "+ ptypes[ptype] + " where name=%s and remote_identifier=%s"""
	cur.execute(qry , (product_name,remote_id))
	id=cur.fetchone()
	cur.close()
	if not id is None : 
		return id[0]
	else:
		return -1

def insert_new(db,product_name,ptype,remote_id):
	global ptypes
	cur=db.cursor()
	##TODO XSS / SQL INJ.
	qry="insert into " + ptypes[ptype] + " (name,remote_identifier) VALUES (%s, %s)"
	cur.execute(qry, (product_name,remote_id,))
	cur.execute("""select last_insert_id()""")
	id=cur.fetchone()[0]
	db.commit()
	cur.close()
	return id
